package com.zhixin.fans.ks.ui.main.service;


import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.PhoneUtils;
import com.qmuiteam.qmui.layout.QMUILinearLayout;
import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.api.CommonApi;
import com.zhixin.fans.ks.api.res.ServiceContactRes;
import com.zhixin.fans.ks.ui.base.BaseDaggerFragment;

import org.eenie.common.subscribes.ProgressSubscriber;
import org.eenie.common.views.TopBarLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class RankFragment extends BaseDaggerFragment {


    @BindView(R.id.top_bar)
    TopBarLayout mTopBar;
    @BindView(R.id.lay_service_call)
    QMUILinearLayout mLayServiceCall;
    @BindView(R.id.lay_service_qq)
    QMUILinearLayout mLayServiceQq;
    CommonApi mCommonApi;
    String service_qq = "1251258765";
    String service_phone = "18152861389";
    @BindView(R.id.tv_phone)
    TextView mTvPhone;
    @BindView(R.id.tv_qq)
    TextView mTvQq;
    @BindView(R.id.tv_wx)
    TextView mTvWx;
    Unbinder unbinder;


    List<TextView> mHints = new ArrayList<>();

    public RankFragment(String title) {
        super(title);
    }

    @Override
    public int initContentView() {
        return R.layout.fragment_rank;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mCommonApi = getApplicationComponent().getApiManager().create(CommonApi.class);
    }

    @Override
    public void initUI(View rootView) {
        unbinder= ButterKnife.bind(this, rootView);

        mHints.add(mTvQq);

        mHints.add(mTvPhone);

        mHints.add(mTvWx);


    }


    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        fetchUserInfo();
    }

    private void fetchUserInfo() {
        mCommonApi.fetchContact()
                .subscribe(new ProgressSubscriber<ServiceContactRes>() {
                    @Override
                    public void onNext(ServiceContactRes contact) {
                        mTvPhone.setText(contact.getCustomerInfo().getCustomerMobile());
                        mTvQq.setText(contact.getCustomerInfo().getCustomerQQ());
                        mTvWx.setText(contact.getCustomerInfo().getCustomerWX());


                        for (TextView view : mHints) {
                            view.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void onFinish() {

                    }
                });
    }

    @OnClick(R.id.lay_service_call)
    public void onMLayServiceCallClicked() {
        PhoneUtils.dial(service_phone);
    }





    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
